package com.kangkang.leetcode10;

import java.util.Arrays;

public class Test3 {
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4}; // 输入数组
        int[] expectedNums = {0,1,2,3,4}; // 长度正确的期望答案

        int k = Solution3.removeDuplicates(nums); // 调用

        assert k == expectedNums.length;
        for (int i = 0; i < k; i++) {
            assert nums[i] == expectedNums[i];
        }
        System.out.println(Arrays.toString(nums));
    }
}
class Solution3 {
    public static int removeDuplicates(int[] nums) {
        int k = 1;
        for (int i = 1; i < nums.length;i++) {
            if (nums[i] != nums[i-1]) {
                nums[k] = nums[i];
                k++;

            }
        }
        return k;
    }

}